package com.xyy.saas.payment.payment.core.conversion;

import com.xyy.saas.payment.common.Constants;
import com.xyy.saas.payment.dao.model.RefundOrder;
import com.xyy.saas.payment.dao.model.WithdrawOrder;
import com.xyy.saas.payment.payment.core.dto.RefundDto;
import com.xyy.saas.payment.payment.core.dto.WithdrawalDto;

import java.util.Date;

/**
 * @author wangtianqi
 * @date 2019/11/25 20:00
 */
public class ConversionDomain {

    public static RefundOrder buildRefundDomain(RefundDto refundDto, boolean needDelay) {
        RefundOrder refundOrder = new RefundOrder();
        refundOrder.setRefundNo(refundDto.getRefundNo());
        refundOrder.setChannelRefundNo("");
        refundOrder.setPayNo(refundDto.getPayNo());
        refundOrder.setChannelChargeNo(refundDto.getChannelChargeId());
        refundOrder.setChannel(refundDto.getChannel());
        refundOrder.setBusinessType(refundDto.getBusinessType());
        refundOrder.setUserId(refundDto.getUserId());
        refundOrder.setAmount(refundDto.getAmount());
        refundOrder.setCreateTime(new Date());
        refundOrder.setUpdateTime(new Date());
        refundOrder.setSuccessTime(new Date(Constants.DEFAULT_UNIX_TIME));
        refundOrder.setStatus(needDelay ? RefundOrder.STATUS_DELAY : RefundOrder.STATUS_CREATE);
        refundOrder.setCallbackAddress(refundDto.getCallbackUrl());
        refundOrder.setBusinessRefundNo(refundDto.getBusinessRefundNo());
        refundOrder.setBusinessOrderType(refundDto.getBusinessOrderType());
        refundOrder.setVersion(0);
        return refundOrder;
    }


    public static WithdrawOrder buildWithdrawDomain(WithdrawalDto withdrawalDto) {
        WithdrawOrder withdrawOrder = new WithdrawOrder();
        withdrawOrder.setWithdrawNo(withdrawalDto.getWithdrawalNo());
        withdrawOrder.setChannelWithdrawNo("");
        withdrawOrder.setChannel(withdrawalDto.getChannelType());
        withdrawOrder.setBusinessType(withdrawalDto.getBusinessType());
        withdrawOrder.setUserId(withdrawalDto.getUserId());
        withdrawOrder.setAmount(withdrawalDto.getAmount());
        withdrawOrder.setFee(withdrawalDto.getFee());
        withdrawOrder.setCreateTime(new Date());
        withdrawOrder.setSuccessTime(new Date(Constants.DEFAULT_UNIX_TIME));
        withdrawOrder.setUpdateTime(new Date());
        withdrawOrder.setStatus(WithdrawOrder.STATUS_IN);
        withdrawOrder.setCallBackUrl(withdrawalDto.getCallbackUrl());
        withdrawOrder.setBusinessWithdrawNo(withdrawalDto.getBusinessWithdrawNo());
        withdrawOrder.setBusinessUserName("");
        return withdrawOrder;
    }
}
